<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
//session_start();
class Login extends CI_Controller {
	public $session;
	public function __construct(){
		parent::__construct();
		$this ->load ->helper('url');	
		$this ->load ->database();

	}
	public function index()
	{
		// print_r($_SESSION);die;
		$this->load->view('admin/login');
	}
	// 登录操作
	public function loginup()
	{
		// 获取验证码  没有大小写验证
		
		//$codeword=$_SESSION['codeword'];
		$codeword=$_SESSION['codeword'];
		// print_r($codeword);die;
		// 接收验证码 没有大小写验证
		$code=$this ->input ->post('code');
		if ($codeword!=$code) {
			echo "验证码错误";
			die;
		}

		// 接收数据
		$admin_pwd=$this ->input ->post('admin_pwd');
		$admin_name=$this ->input ->post('admin_name');
		$admin_pwd=md5($admin_pwd);
		// 验证用户名密码是否正确
		$this ->load ->model('admin');

		$arr=$this ->admin ->loginup($admin_name,$admin_pwd);
		// print_r($arr);die();
		if ($arr) {
			// 存session
			$_SESSION['admin_id'] = $arr['admin_id'];
			$_SESSION['admin_name'] = $arr['admin_name'];
			redirect('admin/admin/index');
		}else{
			redirect('admin/Login/index');
		}
	}
	// 验证码
	public function yzm()
	{
	    
		$this ->load ->helper('Captcha');

		//调用函数生成验证码,上述的参数也可以继续使用  
        $vals = array(  
            'word_length' => 1,
            'word' => rand(1000, 10000),
            'img_width' =>100,
        );  
       create_captcha($vals);
		// print_r($_SESSION);
	}

	/**
	 * 退出登录
	 * */
	public function loginOut()
	{
		//echo 13;die;
		session_unset();
		redirect('admin/Login/index');
	}
	
}






 ?>